/**
 * 
 */

function addFoodToCart(intFoodId, intQuantity) {
	var food_icon_id = "#food_icon_"+intFoodId;
	//$(food_icon_id).css("position","relative");
	
	//alert($("#miniFoodPicDiv").html());
	var oldTop = $(food_icon_id).offset().top;
	var oldLeft = $(food_icon_id).offset().left;
	var newTop = $("#cart").offset().top;
	var newLeft = $("#cart").offset().left;
	var cartHeight =  $("#cart").height();
	var cartWidth =  $("#cart").width();
		
	//var relativeTop = newTop - oldTop;
	//var relativeLeft = newLeft - oldLeft;
	
	if ($(food_icon_id).find("img").size() != 0){
		var miniFoodPic = $("body").append("<div id='miniFoodPicDiv'>"+$(food_icon_id).html()+"</div>");
	}
	else{
		var miniFoodPic = $("body").append("<div id='miniFoodPicDiv'>"+"<img src='/images/restaurantHome/button-add.png'/>"+"</div>");
	}
	
	
	var miniFoddPicDiv = $("#miniFoodPicDiv");
	miniFoddPicDiv.css("position","absolute");
	miniFoddPicDiv.css("left",oldLeft);
	miniFoddPicDiv.css("top",oldTop);
	
	//alert(oldTop+" "+oldLeft);
	miniFoddPicDiv.animate({top:(newTop+cartHeight/2)+"px",left:(newLeft+cartWidth/2)+"px",width:"0px",height:"0px",opacity:0.3},"slow",function removeMiniDiv(){
		//$(miniFoddPicDivID).hide(100);
		//alert(miniFoddPicDivID);
		$("#miniFoodPicDiv").remove();
	});
	
	//$(food_icon_id).hide();
	var actionURL = "/index.php/cart/addFood/" + intFoodId + "/"+intQuantity;
	sendUrl("addFoodToCart", actionURL);	
}


function substractFood(intFoodId, intQuantity) {
	var actionURL = "/index.php/cart/substractFood/" + intFoodId + "/"+intQuantity;
	sendUrl("substractFood", actionURL);	
}

function removeFood(intFoodId) {
	var actionURL = "/index.php/cart/removeFood/" + intFoodId;
	sendUrl("removeFood", actionURL);
}

function sendUrl(actionName, actionURL) {
	$('#cart_ajax_loading_div').show();
	$('#cart_food_list').addClass('cart_food_list_transparent');
	
	$.ajax({
		type : "POST",
		url : actionURL,
		cache : false,
		beforeSend : function() {
			printOut("jquery");
			printOut(actionName + " beforeSend  " +actionURL);
		},
		success : function(cartPanelHTML) {
			printOut(actionName + "success cart");
			//printOut(actionName + cartPanelHTML);
			$("#cart").html(cartPanelHTML);
		},
		error : function(XMLHttpRequest) {
			alert("error");
		},
		complete : function(XMLHttpRequest) {
			printOut(actionName + " complete cart"+"<br>");
			$('#cart_ajax_loading_div').hide();
			$('#cart_food_list').removeClass('cart_food_list_transparent');
			  
		}
	});
	return;
	/**/
	Vancl_ajax({
		async : true,
		cache : false,
		type : "POST",
		url : actionURL,
		data : "",
		beforeSend : function() {
			printOut(actionURL + " beforeSend " +actionURL);
		},
		success : function(cartPanelHTML) {
			printOut(actionName + "success cart");
			//printOut(actionName + cartPanelHTML);
			$("#cart").html(cartPanelHTML);
		},
		error : function(XMLHttpRequest) {
			alert("error");
		},
		complete : function(XMLHttpRequest) {
			printOut(actionName + " complete cart"+"<br>");
		}
	});
}
